<template>
  <view class="w-full">
    <Card v-for="order in filterOrders" v-bind="order" :key="order._id" />
  </view>
</template>

<script setup>
import Card from '../../components/Card.vue';
import { useDocumentsStore } from '../../stores/documents';
import { useFavoriteStore } from '../../stores/favorite'
import { useUserStore } from '../../stores/user'
import { onShow } from "@dcloudio/uni-app"
import { computed, onBeforeMount } from 'vue'

const user = useUserStore()
const documents = useDocumentsStore()
const favorite = useFavoriteStore()


onShow(() => {
  favorite.getOrders()
  documents.getOrders()
  user.getMyWorks()
  user.getMyPublish()
  console.log('onshow')
})

onBeforeMount(async () => {
  await user.getUser() // getUser返回的是promise，用await等待，获取用户信息后再获取订单信息
  user.getMyWorks()
  user.getMyPublish()
})
uni.setNavigationBarTitle({ title: '镇镇求职 | ' + user.area })

const filterOrders = computed(() => {
  return documents.orders.reverse()
})
</script>

